home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9039 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: news.bridge.net!news
  2. From: David Byrden <100101.2547@compuserve.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: C++ OO question (long)
  5. Date: 28 Feb 1996 04:34:45 GMT
  6. Organization: self-employed
  7. Message-ID: <4h0m15$kps@news.bridge.net>
  8. References: <4h08uq$mve@madeline.INS.CWRU.Edu>
  9. NNTP-Posting-Host: ppp-mia4-144.bridge.net
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.1N (Windows; I; 16bit)
  14.  
  15.  
  16. Bryan;
  17.  
  18.   When you define a copy ctor for a class, you usually need to define an 
  19. assignment operator  
  20.  
  21.         Matrix& operator=( const Matrix& other )
  22.  
  23. as well. If not, the compiler generates a 'stupid' one and this is the 
  24. cause of your crash. 
  25.  
  26.   Your operator= should;
  27.      Do nothing if its object is being assigned to itself
  28.      Get rid of current data
  29.      Make copy of 'other' data
  30.      Return a reference to itself
  31.  
  32.  
  33.   Also: when you declare with the assigment operator, the copy ctor is 
  34. called. The new syntax is therefore preferred, though it means the same 
  35. thing
  36.  
  37.   Matrix M3( M2 * M1 ) ;
  38.  
  39.  
  40.   Also: I notice that your binary operators look like this;
  41.  
  42.  
  43.    Matrix operator * (Matrix, Matrix);  
  44.  
  45.  
  46.  When you pass a Matrix by value, an ENTIRE MATRIX will be made using the 
  47. copy ctor. This is not necessary.   operator+ does not modify its 
  48. argumenfs, so pass const references instead.
  49.  
  50.  
  51.                            David
  52.  
  53.  
  54.  
  55.